using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using SQLDAL;

public partial class GUI_Webpage_Manager_Statistic : System.Web.UI.Page
{
    #region Fields

    SqlDataReader reader = null;
    RestaurantBll restaurantBll = new RestaurantBll();
    BookingTableBll bookingTableBll = new BookingTableBll();
    OrderFoodBll orderFoodBll = new OrderFoodBll();
    BookingTableDetailsInfo bookingTableDetailsInfo = new BookingTableDetailsInfo();
    OrderFoodInfo orderFoodInfo = new OrderFoodInfo();
    RestaurantInfo resInfo = new RestaurantInfo();
    string service = null;
    string timeSelect = null;

    #endregion

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            restaurantBll.LoadRestaurant(drpRestaurant);
        }
    }

    protected void btnAccept_Click(object sender, EventArgs e)
    {
        if(IsPostBack)
        LoadData(); 
    }

    protected void drpRestaurant_SelectedIndexChanged(object sender, EventArgs e)
    {
        resInfo.ResID = drpRestaurant.SelectedValue.ToString();
    }

    protected void rbChooseDay_SelectedIndexChanged(object sender, EventArgs e)
    {
        timeSelect = rbChooseDay.SelectedValue.ToString();
    }

    protected void rbChoose_SelectedIndexChanged(object sender, EventArgs e)
    {
        service = rbChoose.SelectedValue.ToString();
    }

    #region Load all table booking by the standart want to statistic
    public void LoadData()
    {
        // if choose Table Booking 
        if (rbChoose.SelectedValue.ToString() == "Table booking")
        {
            // assign resID to resInfo object
            resInfo.ResID = drpRestaurant.SelectedValue.ToString();
            // if choose By DATE
            if (rbChooseDay.SelectedValue.ToString() == "By date")
            {
                bookingTableDetailsInfo.DateBooking = DateTime.Parse(txtText.Text);
                reader = bookingTableBll.ListAllTableBookingOfRestaurantByDate(bookingTableDetailsInfo, resInfo);
            }
            // if choose BY MONTH
            else if (rbChooseDay.SelectedValue.ToString() == "By month")
            {
                reader = bookingTableBll.ListAllTableBookingOfRestaurantByMonth(int.Parse(txtText.Text), resInfo);
            }
            // if choose BY YEAR
            else if (rbChooseDay.SelectedValue.ToString() == "By year")
            {
                reader = bookingTableBll.ListAllTableBookingOfRestaurantByYear(int.Parse(txtText.Text), resInfo);
            }
        }
        // if choose FOOD ORDER
        else if (rbChoose.SelectedValue.ToString() == "Food order")
        {
            resInfo.ResID = drpRestaurant.SelectedValue.ToString();
            if (rbChooseDay.SelectedValue.ToString() == "By date")
            {
                orderFoodInfo.DateOfOrder = DateTime.Parse(txtText.Text);
                reader = orderFoodBll.ListAllFoodOrderOfRestaurantByDate(orderFoodInfo, resInfo);
            }
            else if (rbChooseDay.SelectedValue.ToString() == "By month")
            {
                reader = orderFoodBll.ListAllFoodOrderOfRestaurantByMonth(int.Parse(txtText.Text), resInfo);
            }
            else if (rbChooseDay.SelectedValue.ToString() == "By year")
            {

                reader = orderFoodBll.ListAllFoodOrderOfRestaurantByYear(int.Parse(txtText.Text), resInfo);
            }
        }
        //bind data to gridview
        grvListStatistic.DataSource = reader;
        grvListStatistic.DataBind();
    }
    #endregion
}
